package com.cxs.musicplaywidget.util;

public class DateUtils {
    // 1s = 1000ms
    private static final int One_Sec_Ms = 1000;
    // 1min = 60s
    private static final int One_Min_Sec = 60;
    // 1h = 60min
    private static final int One_Hour_Min = 60;

    // 毫秒数转换为时间
    public static String msToTimeString(int ms) {
        try {
            int seconds = ms / One_Sec_Ms;    // 总秒数
            int minutes = seconds / One_Min_Sec;  // 总分钟 = 总秒数 / 60
            int second = seconds % One_Min_Sec;   // 剩余秒数 = 总秒数 % 60

            int hour = minutes / One_Hour_Min;    // 总小时数 = 总分钟 / 60
            int minute = minutes % One_Hour_Min;  // 剩余分钟 = 总分中 % 60
            String formatHour = String.format("%02d", hour);
            String formatMin = String.format("%02d", minute);
            String formatSec = String.format("%02d", second);

            if (hour > 0) {
                return formatHour + ":" + formatMin + ":" + formatSec;
            } else {
                return formatMin + ":" + formatSec;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "0";
        }

    }
}
